
Partial Class Store_ShowProduct
    Inherits System.Web.UI.Page

    Private _ASIN As String = ""
    Dim product As New ProductObj

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If String.IsNullOrEmpty(Me.Request.QueryString("ID")) Then
            Throw New ApplicationException("Missing parameter on the querystring.")
        Else
            _ASIN = Me.Request.QueryString("ID").ToString
        End If

        If Not Me.IsPostBack Then
            ' try to load the product with the specified ID, and raise an exception if it doesn't exist
            product = product.GetProductByID(_ASIN)

            If product Is Nothing Then
                Throw New ApplicationException("No product was found for the specified ID.")
            End If

            ' display all article's data on the page
            Me.Title = String.Format(Me.Title, product.Title)
            lblTitle.Text = product.Title

            lblDescription.Text = product.Description

            lblPrice.Text = product.ListPrice
            lblDiscountedPrice.Text = product.Price

            If product.ImageURL.Length > 0 Then
                imgProduct.ImageUrl = product.ImageURL
            End If

        End If
    End Sub

    Protected Sub btnAddToCart_Click(ByVal sender As Object, ByVal e As EventArgs)
        product = product.GetProductByID(_ASIN)
        Me.Profile.ShoppingCart.InsertItem(_ASIN, product)
        Me.Response.Redirect("ShoppingCart.aspx", False)
    End Sub

End Class
